package me.hetong.caigou.ui;

import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import me.hetong.caigou.Global;
import me.hetong.caigou.entity.MessageBean;
import me.hetong.caigou.entity.View;
import me.hetong.caigou.ui.stage.IndexStage;

import static me.hetong.caigou.Global.config;

public class ViewFactory {
    public static View build(Pane pane) {

        AnchorPane anchorPane = new AnchorPane();
        anchorPane.getChildren().add(pane);

        int width = config.getLeftWidth() + config.getRightWidth();
        int height = config.getHeight();

        anchorPane.setPrefSize(width, height);
        anchorPane.setMaxSize(width, height);
        anchorPane.setMinSize(width, height);

        pane.setStyle("-fx-background-color: " + config.getBackgroundColor());
        pane.setPrefSize(width, height);
        pane.setMaxSize(width, height);
        pane.setMinSize(width, height);

        Scene scene = new Scene(anchorPane);

        Stage stage = new Stage();
        stage.setScene(scene);
        stage.initModality(Modality.APPLICATION_MODAL);
        stage.initStyle(StageStyle.TRANSPARENT);

        View view = new View();
        view.setRoot(anchorPane);
        view.setScene(scene);
        view.setStage(stage);
        view.setMessageBean(new MessageBean(anchorPane));

        Global.rightMouseDrag(stage);

        return view;

    }

    public static View buildPop(Pane pane) {

        AnchorPane anchorPane = new AnchorPane();
        anchorPane.getChildren().add(pane);

//        double width = config.getRightWidth();
//        double height = config.getHeight();
//
//        anchorPane.setPrefSize(width, height);
//        anchorPane.setMaxSize(width, height);
//        anchorPane.setMinSize(width, height);

        pane.setStyle("-fx-background-color: " + config.getBackgroundColor());
//        pane.setPrefSize(width, height);
//        pane.setMaxSize(width, height);
//        pane.setMinSize(width, height);

        Scene scene = new Scene(anchorPane);

        Stage stage = new Stage();
        stage.setScene(scene);
        stage.initModality(Modality.APPLICATION_MODAL);
        stage.initStyle(StageStyle.TRANSPARENT);
//        stage.setX(IndexStage.VIEW.getStage().getX()-config.getLeftWidth());

        View view = new View();
        view.setRoot(anchorPane);
        view.setScene(scene);
        view.setStage(stage);

        return view;

    }
}
